home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1987 / 06 / capslock.asm < prev    next >
Assembly Source File  |  1987-08-07  |  7KB  |  204 lines

  1. ;--------------------------------------------------------------------
  2. ;   Code For "The Case of the Invisible CapsLock" by Tom Swan
  3. ;        Page 24, Volume 5.5, Programmer's Journal
  4. ;--------------------------------------------------------------------
  5. ;
  6. ;  PURPOSE      : CapsLock Cursor Display program (TSR)
  7. ;
  8. ;  SYSTEM       : IBM PC-DOS
  9. ;
  10. ;  LANGUAGE     : Microsoft Macro Assembler (MASM)
  11. ;
  12. ;  AUTHOR       : (C) 1987 by Tom Swan, Swan Software, P.O. Box
  13. ;                 206, Lititz, PA 17543 
  14. ;
  15. ;--------------------------------------------------------------------
  16. ;----- Equates
  17.  
  18. cr              equ     13              ;ASCII carriage return
  19. lf              equ     10              ;ASCII line feed
  20. caps            equ     040h            ;CapsLock kbflag bit
  21. monochrome      equ     7               ;Monochrome video mode
  22. last8x8mode     equ     0eh             ;If <=, assume 8x8 chars
  23. fatStart14      equ     7               ;14-line cursor fat
  24. thinStart14     equ     11              ; and thin start/end lines
  25. endLine14       equ     12
  26. fatStart8       equ     3               ;8-line cursor fat
  27. thinStart8      equ     6               ; and thin start/end lines
  28. endLine8        equ     7
  29.  
  30.  
  31. BIOSDATA        SEGMENT AT 40H
  32.  
  33. kbflag          equ     017h            ;Keyboard flag offset
  34. crtmode         equ     049h            ;Current video mode
  35. BIOSDATA        ENDS
  36.  
  37.  
  38. ;----- Start of Program
  39.  
  40. CSEG            SEGMENT byte
  41.                 ASSUME  cs:CSEG,ds:CSEG,ss:CSEG,es:CSEG
  42.                 ORG     100h            ;com file entry point
  43.  
  44. CapsLock:       jmp     short init      ;jump to initialize program
  45.  
  46.  èpage;----------------------------------------------------------
  47. ; INT9
  48. ;----------------------------------------------------------
  49. ; Purpose       -- Trap keyboard interrupt #9 on every
  50. ;                   keypress.  Set cursor according to
  51. ;                   current CapsLock/NumLock settings
  52. ;                   then continue with normal interrupt.
  53. ;
  54. ; Called by     -- Keyboard hardware interrupt (#9)
  55. ;
  56. ; Calls         -- Jumps to pre-installation code
  57. ;                  Does not call DOS
  58. ;
  59. ; Arguments     -- none
  60. ;
  61. ; Registers     -- none changed
  62. ;----------------------------------------------------------
  63.  
  64.         ASSUME  cs:CSEG, ds:BIOSDATA
  65.  
  66. oldcaps db      0               ;last known capslock setting
  67. int9    PROC    near
  68.  
  69.         pushf                   ; save flags & registers
  70.         push    ax
  71.         push    cx
  72.         push    ds
  73.  
  74.         mov     ax,BIOSDATA     ;set dsregister to
  75.         mov     ds,ax           ; BIOS data segment
  76.         mov     ah,byte ptr [ds:kbflag]         ;get keyboard flag
  77.         and     ah,caps         ;isolate capslock bit
  78.         cmp     ah,byte ptr [cs:oldcaps]        ;compare old setting
  79.         je      exit            ;exit if not changed
  80.         mov     byte ptr[cs:oldcaps],ah         ;save new setting
  81.         mov     al,byte ptr [ds:crtmode]        ;get video mode
  82.         cmp     al,monochrome   ;if monochrome
  83.         je      line14          ; then use 14-line cursor settings
  84.         cmp     al,last8x8mode  ;else if less than this
  85.         jle     line8           ; then use 8-line cursor settings
  86.  
  87. line14:
  88.         mov     al,fatStart14   ; 14-line cursors
  89.         mov     ch,thinStart14
  90.         mov     cl,endLine14
  91.         jmp     short change
  92.  
  93. line8:
  94.         mov     al,fatStart8    ; 8-line cursors
  95.         mov     ch,thinStart8
  96.         mov     cl,endLine8
  97.  
  98.  
  99. ;----- Change cursor style.  At this point, ah=capslock bit,
  100. ;      al=fat start line, ch=thin startline, cl=end line èchange:
  101.         or      ah,ah           ;test capslock setting
  102.         jz      nocaps          ;jump if key is off (thin style)
  103.         mov     ch,al           ;else switch to fat style
  104.  
  105. nocaps:
  106.         mov     ah,1            ;select cursor style
  107.         int     10h             
  108. ;execute BIOS video I/O interrupt
  109.  
  110. exit:
  111.         pop     ds              ;restore registers & flags
  112.         pop     cx
  113.         pop     ax
  114.         popf
  115.  
  116.  
  117. ;----- The following reserves space fora far jump instruction,
  118. ;      filled in by the initialization code.  This lets the program
  119. ;      continue to the original address that handled this interrupt
  120. ;      before installing the TSR code.
  121.  
  122.         db      0eah    ;ea=far jump hex code
  123.  
  124. address:
  125.         dd      0       ;32-bit jump address (unitialized)
  126.  
  127. int9    ENDP            ;end of procedure
  128.  
  129.  
  130. page
  131. ;----------------------------------------------------------
  132. ; INIT
  133. ;----------------------------------------------------------
  134. ; Purpose       -- Initialize interrupt trap, terminate
  135. ;                   program and stay resident.  All code
  136. ;                   from this point on is NOT saved
  137. ;                   in memory.  Everything before stays.
  138. ;
  139. ; Called by     -- Main program (via jmp)
  140. ;
  141. ; Calls         -- DOS
  142. ;----------------------------------------------------------
  143.  
  144.         ASSUME  cs:CSEG,ds:CSEG
  145.  
  146. init    PROC    near
  147.         mov     dx,offset id    ;print program id
  148.         mov     ah,9
  149.         int     21h
  150.  
  151.  
  152. ;----- Get vector to current interrupt #9 routine
  153.  
  154.         mov     ax,3509h        ;ah=35 è(get vector)
  155.                                 ;al=09 
  156. (vector number)
  157.         int     21h             ;set es:bx to current vector
  158.  
  159.  
  160. ;----- Insert vector as far jump address at end of resident code
  161.  
  162. init1:  mov     word ptr address,bx     ;set far jmp offset address
  163.         mov     word ptr address+2,es   ;set far jmp segment address
  164.  
  165. ;----- Change interrupt vector to the new TSR routine.
  166.  
  167.         mov     dx,offset int9  ;dx=address of routine
  168.         mov     ax,2509h        ;ah=25(set vector)
  169.                                 
  170. ;al=09(vector number)
  171.         int     21h             ;set interrupt 9 vector
  172.  
  173.  
  174. ;----- Make sure capslock bit is off.
  175.  
  176.         ASSUME  ds:BIOSDATA
  177.  
  178.         push    ds
  179.         mov     ax,BIOSDATA
  180.         mov     ds,ax           ;address BIOS data segment
  181.         and     byte ptr [ds:kbflag],not caps   ; turn off caps
  182.         pop     ds
  183.  
  184.         ASSUME  ds:CSEG
  185.  
  186.  
  187. ;----- Terminate and stay resident (TSR).
  188.  
  189.         mov     dx,offset init  ;dx = first available address
  190.         int     27h             ;terminate, stay resident
  191. init    ENDP                    ;end ofprocedure
  192.  
  193.  
  194. ;----- Program variables.
  195.  
  196. id      db      cr,lf, 'CapsLock Cursor Display Program'
  197.         db      cr,lf, '(C) 1987 by TomSwan'
  198.         db      cr,lf, 'Swan Software, PO Box 206, Lititz PA  17543'
  199.         db      cr,lf, '$'
  200.  
  201. CSEG    ends                    ;end ofsegment
  202.         end     CapsLock        ;end of program
  203.  
  204.